package com.game.majiang.vo;

import java.sql.Types;
import java.util.ArrayList;

import javax.sql.rowset.CachedRowSet;

import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.manager.RankingManager;
import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;
import com.game.server.db.entity.JiangliLog;

public class ProxyPumpLogVo {

	
	public static void insert(int uid, int gold, int cuid, int tableid, int allpump, int dengji, int paiming) {
		String sql = "INSERT INTO proxypumplog (uid,gold,cuid,tableid,allpump,dengji,paiming) "
				+ "VALUES (?,?,?,?,?,?,?)";
		Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, gold, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, cuid, ParameterType.Input);
		Parameter p4 = new Parameter(Types.INTEGER, tableid, ParameterType.Input);
		Parameter p5 = new Parameter(Types.INTEGER, allpump, ParameterType.Input);
		Parameter p6 = new Parameter(Types.INTEGER, dengji, ParameterType.Input);
		Parameter p7 = new Parameter(Types.INTEGER, paiming, ParameterType.Input);
		SqlHelperwrite.execute(sql, p1,p2,p3,p4,p5,p6,p7);
	}
	//查今日新增红利   等级分
	public static int selectToDay(int uid, int dengji) {
		String sql = "SELECT SUM(gold) as golds FROM proxypumplog WHERE uid = ? "
				+ "AND TO_DAYS(createtime) = TO_DAYS(NOW()) AND dengji = ? ";
		Parameter p1 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER, dengji, ParameterType.Input);
		Object execScalar = SqlHelper.execScalar(sql, p1,p2);
		if (execScalar == null) {
			return 0;
		}
		Long l = (Long)execScalar;
		return l.intValue();
	}
	//查用户的红利记录
	public static ArrayList<JiangliLog> selectUserLog(int uid) {
		ArrayList<JiangliLog> list = new ArrayList<>();
		String sql = "SELECT u1.id,u1.head,u1.nickname,p1.gold,p1.createtime,p1.paiming FROM "
				+ "(SELECT gold,cuid,createtime,paiming FROM proxypumplog WHERE uid = ?) p1 "
				+ "LEFT JOIN users u1 ON u1.id = p1.cuid ORDER BY p1.createtime DESC";

		Parameter p1 = new Parameter(Types.INTEGER, uid,ParameterType.Input);
		CachedRowSet resultSet = SqlHelper.getResultSet(sql, p1);
		try {
			while (resultSet.next()) {
				JiangliLog jl = new JiangliLog();
				jl.id = resultSet.getInt("id");
				jl.head = resultSet.getString("head");
				jl.name = resultSet.getString("nickname");
				jl.gold = resultSet.getInt("gold");
				jl.createtime = resultSet.getString("createtime");
				jl.paiming = resultSet.getInt("paiming");
				list.add(jl);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
		
	}
	
	
}
